<template>
  <div>
    <Header></Header>
    <div class="mainBox w1200 bc mt20 clearfix">
      <userSideMenu :flag="'travel'"></userSideMenu>
      <div class="mainRight fr w930">
        <!--收藏的游记-->
        <div class="br2 bg100 pb60">
          <!--title-->
          <h1 class="h60 bb90  c60 clearfix ">
            <a class="fl h60 f18 fm-yahei  lh60 c0 ml25" href="javascript:void (0);">我发表的游记</a>
          </h1>
          <!--list-->
          <ul class="w880 pl25 pr25  c60 f12 lh18 fm-yahei  pointer" ref="infoListBox">
            <travelItem v-for="travel in travelList" :travel = "travel"></travelItem>
            <li class="tc c60 f12 lh60">
              <a class="c60 hoverfont_unl" href="javascript:void(0);" @click = "getMoreTravel">点击查看更多></a>
            </li>
          </ul>
        </div><!--热门活动结束-->

      </div><!--mainRight结束-->
    </div>
    <Footer></Footer>
    <loading v-show = "loadState"></loading>
  </div>
</template>

<script>
  import Header from "../../components/header";
  import Footer from "../../components/footer";
  import userSideMenu from "../../components/usersidemenu";
  import travelItem from "../../components/travelItem";
  import Utils from "../../assets/Util";
  import loading from "../../components/loading";
  export default {
    name: 'userTravel',
    components:{
      Header,
      Footer,
      userSideMenu,
      travelItem,
      loading
    },
    data(){
      return {
        loadState:true,
        travelList:[],
        getTravelData:{
          "type": 2,
          "userID": localStorage.getItem("uId"),
          "token": localStorage.getItem('token'),
          "pageIndex": 0,
          "pageSize": 5,
          "variety": 2
        }
      }
    },
    mounted(){
      if (!Utils.isLogin){
        this.$router.push({path:'/'})
      }
      this.getTravels();
    },
    methods:{
      // 请求活动列表
      getTravels(){
        let props = {
          url:"/Activity/GetList",
          data:this.getTravelData,
          sCallBack:res => {
            this.loadState = false;
            if(res.data.code === 1){
              if(res.data.data.length === 0){
                if (this.getTravelData.pageIndex === 0){
                  this.$refs.infoListBox.innerHTML = " <li class=\"tc c60 f12 lh60 mt20\">\n" +
                    "                <a class=\"c60 hoverfont_unl\" href=\"javascript:void(0);\">暂无数据</a>\n" +
                    "              </li>"
                  return false;
                }
                this.$message.success("全部加载完毕");
                return false;
              }
              this.travelList = this.travelList.concat(res.data.data);
            }else if(res.data.code === 4){
              this.refreshToken(this.getTravels);
            }else{
              this.$message.error("游记信息请求出错");
            }
          },
          eCallBack:err => {
            this.$message.error("活动请求失败");
            console.log(err);
          }
        }
        Utils.myRequest(props);
      },
      getMoreTravel(){
        this.loadState = true;
        this.getTravelData.pageIndex += 1;
        this.getTravels();
      },
    }
  }
</script>

<style scoped>

</style>
